/******************************************************************************\
    HttpProxyClient.h discribes a class for a client of http proxy.
    It's used with acm server. See main.cpp for details.
    Copyright (C) 2008  Victor Vinogradov (fly3333@gmail.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
\******************************************************************************/

#pragma once 

#include <Common\BaseThread.h>
#include <Common\CriticalSection.hpp>
#include <Common\Socket.hpp>

class cWardHttpProxyClient : public cBaseThread
{
private:
	//bool IsNeedToStop;
	cCriticalSection CriticalSection;

	cSocket Socket;
protected:
	virtual unsigned long Process();
public:
	cWardHttpProxyClient( const cSocket &socket );
	~cWardHttpProxyClient();
	friend class cHttpProxyClient;
};

class cHttpProxyClient : public cPointerObject< cWardHttpProxyClient >
{
public:
	bool Create( const cSocket &socket )
	{
		cWardHttpProxyClient *ward_http_proxy_client;
		try
		{
			ward_http_proxy_client = new cWardHttpProxyClient( socket );
		}
		catch( ... )
		{
			return false;
		}
		if( ward_http_proxy_client->Thread == INVALID_HANDLE_VALUE ||
			 ward_http_proxy_client->Thread.Resume() == -1 ||
			 !SwitchToWardObject( ward_http_proxy_client ) )
		{
			delete ward_http_proxy_client;
			return false;
		}
		return true;
	}
	void Destroy()
	{
		SwitchToSubObject( NULL );
	}
};
